<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
	session_start();
	$dbconn = pg_connect("host=localhost port=5432 dbname=CinemaEnri user=postgres password=Quie1hoh");
	if (!$dbconn){
			die("Errore di connessione al database" . pg_last_error());
	}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="Css/screen.css" rel="stylesheet" type="text/css" media="screen"/>
<script language="JavaScript" type="text/JavaScript" src="Function.js" ></script>
<title>Cinema Enri - Modifica Attori</title>
</head>

<body>
<div id="logo"><img src="Images/Logo.jpg" width="220" height="100"/></div>
        <div id="Header">
             <div id="cerca">
                
            </div>
        </div>
        <div id="main">
            <div id="menu">
                <ul>
                	<div id="infoCinema">
                    	<div class="titolo">Info Cinema</div>
                        <li><a href="Index.php">Home</a></li>
                        <li><a href="Programmazione.php">Programmazione</a></li>
                    </div>
                     <?php
						$user=$_SESSION['User'];
						$admin=$_SESSION['Admin'];
						if (isset($user)){
					?>
                    <div id="utente">
                    	<div class="titolo">Servizi Utente</div>
                        <li><a href="Prenotazioni.php">Prenota un film</a></li>
                        <li><a href="PaginaPersonale.php">Pagina Personale</a></li>
                    </div>
                    <?php
						}
						if ($admin=="t"){
					?>
                    <div id="admin">
                    	<div class="titolo">Amministratore</div>
                        <li><a href="InsSpettacoli.php">Inserimento Spettacoli</a></li>
                        <li><a href="ModSpettacoli.php">Modifica Spettacoli</a></li>
                        <li><a href="InsFilm.php">Inserimento Film</a></li>
                        <li><a href="ModFilm.php">Modifica Film</a></li>
                        <li><a href="InsAttori.php">Inserimento Attori</a></li>
                        <li><a href="ModAttori.php">Modifica Attori</a></li>
                        <li><a href="InsProduzioni.php">Inserimento Produzioni</a></li>
                        <li><a href="ModPrenotazioni.php">Modifica Prenotazioni</a></li>
                    </div>
					<?php
						}
					?>
                <ul>
            </div>
            <div id="path">
            </div>
            <div id="content">
            	<h1>Modifica informazioni attori e registi</h1>
                
                <?php
				
					$admin=$_SESSION['Admin'];
					if ($admin=="t"){
						$id=$_POST['attore'];
					
						
						$qry = 'SELECT * FROM "tblCast" ORDER BY "Cognome"';
						$result = pg_query($dbconn, $qry);
			
						echo "<form action=ModAttori.php method=post >";
						echo "<select name=attore class=textfield>";
						while($riga = pg_fetch_assoc($result)) {
							if ($riga['ID'] == $id)
								echo "<option value = ".$riga['ID']." selected=selected>".$riga['Cognome'].", ".$riga['Nome']."</option>";
							else
								echo "<option value = ".$riga['ID']." >".$riga['Cognome'].", ".$riga['Nome']."</option>";
						}
						echo "</select>";
						echo "<br /><input type=submit value=Modifica /></form>";
						if(isset($id)){
							$qry = "SELECT * FROM \"tblCast\" WHERE \"ID\"=".$id."";
							$result = pg_query($dbconn, $qry);
				
							while($riga = pg_fetch_assoc($result)) {
					
								echo "<form action=ModAttoriOK.php method=post>";
								echo "<input type=hidden name=id value=".$id." /> &nbsp; &nbsp;";
								echo '<h2>Nome: </h2><input type=text name=nome value="'.$riga['Nome'].'" class=textfield />';
								echo '<h2>Cognome: </h2><input type=text name=cognome value="'.$riga['Cognome'].'" class=textfield />';
		  						echo '<h2>Nazionalità: </h2><input type=text name=nazionalita value="'.$riga['Nazionalita'].'" 
									  class=textfield />';
								echo '<h2>Anno di Nascita: </h2><input type=text name=anno value="'.$riga['AnnoNascita'].'" 
								      class=textfield />';
								echo "<br /><input type=submit value=Salva></form>";
							}
						}
						
						
					}
					else{
						echo "Accesso vietato alla pagina"; 
					 
					}
				?>
                
            </div>
            
            <div id="menuDestro">
                <div id="login" >
                	<?php
						$user=$_SESSION['User'];
					 	if (isset($user)){
								echo "<h2>Stato</h2>";
								echo "<h3>Benvenuto ".$user."</h3>";
								echo "<a href=LogOut.php>LogOut</a>";
						}else{
					?>
                	<h2>Login</h2>
                	<form action="Index.php" method="post">
                    	Username:<input type="text" name="Username" />
                        Password:<input type="password" name="Password" />
                        <input type="submit" value="Login" />
                         Se non sei registrato: <a href="Registrazione.php" >Registrati</a>
                    </form>
                   <?php
						}
				   ?>
                </div>
            </div>
       </div>
</div>



</body>
</html>